<!DOCTYPE html>
<html lang="en" xmlns:sec="http://www.thymeleaf.org/extras/spring-security" xmlns:th="http://www.thymeleaf.org">
<head>
  <th:block th:include="common :: header('添加幻灯片')"/>
  <style>
        .layui-form-label{
            width:80px;
        }
    </style>
</head>
<body>
<form action="" class="layui-form">
  <div class="">
      <div class="main-container">
        <div class="layui-form-item">
          <label class="layui-form-label">名称</label>
          <div class="layui-input-block">
            <input autocomplete="off" class="layui-input" lay-verify="title" name="name" placeholder="请输入标题"
                   type="text">
          </div>
        </div>
        <div class="layui-form-item layui-form-text">
          <label class="layui-form-label">备注</label>
          <div class="layui-input-block">
            <textarea class="layui-textarea" name="remark" placeholder="请输入备注"></textarea>
          </div>
        </div>
        <div class="layui-form-item">
          <div class="layui-input-block">
            <button class="pear-btn pear-btn-primary" lay-submit lay-filter="formDemo">保存</button>
          </div>
        </div>
    </div>
  </div>
</form>
</body>

<th:block th:include="common :: footer"/>
<script>
    layui.use(['form', 'jquery', 'layer'], function () {
        let form = layui.form;
        let $ = layui.jquery;
        let layer = layui.layer;

        form.on('submit(formDemo)', function (data) {
            $.ajax({
                url: '/admin/slide/addPost',
                data: JSON.stringify(data.field),
                dataType: 'json',
                contentType: 'application/json',
                type: 'post',
                success: function (result) {
                    if (result.code) {
                        layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                            parent.layui.table.reload("slide-table");
                        });
                    } else {
                        layer.msg(result.msg, {icon: 2, time: 1000});
                    }
                }
            })
            return false;
        });
    })
</script>
</html>